	// 生成TABLE
    /*
     * row 生成table的行数
     * cell生成table的列数
     * tdWidth生成table的每一个td的width
     * trWidth如果页面拉伸，剩余的td的width，可以为不传入
     */
	function init(row, cell, tdWidth, trWidth){  
	     _table=document.getElementById("searchHeader");
		 _table.border="0px";
		 //_table.setAttribute("width", tbWidth);
		 _table.setAttribute("style", "text-align: left");
		 //_table.setAttribute("class","TableBlock");

	 	var i_width = tdWidth.split(",");
        
	 	var width = 0;
	 	for(var i=0;i<row;i++){
			 var tr=document.createElement("tr");
			 tr.id=i;
			 for(var j=0;j<cell;j++){
				 var td=document.createElement("td");
				 //td.setAttribute("width", i_width[j]+"px");
				 td.setAttribute("id", i+"_"+j);
				 td.setAttribute("style","padding-top:2px;padding-right:2px;width:"+i_width[j]+"px;");
				 //td.appendChild(document.createTextNode("")); 
				 tr.appendChild(td);
				 if (i==0){
					 width = Number(width) + Number(i_width[j]);
				 }
			 }
			 var td=document.createElement("td");
			 td.setAttribute("style", "width:auto;");
			 tr.appendChild(td);
			 
			 document.getElementById("newbody").appendChild(tr);  
		 }
	 	 //_table.setAttribute("width", width+'px');
	 }

	//生成TABLE内容
	/*
	 * row 插入的行
	 * cell插入的列
	 * obj 插入的标签类型
	 * id  插入的标签的ID或者Name
	 * value 传入的值,可以为 不传入
	 */
	function addCommon(row,cell,obj,id,value,event,qid){
	    var text="";
	    //生成文本框
	    if(obj =="lable"){//生成标签
			text = id;
		}else if (obj=="txt")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的内容
		    text+="<input class='searchString' id='"+id+"' name='"+id+"' type='text' value='' style='width:99%'></span>";
		    //查询的操作
		    //text+="<select type='hidden' class='searchOper'><option value='cn'>%</option><option value='eq'>=</option></select></span>";
		}else if (obj=="txtlike")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='cn' >";
		    //查询的内容
		    text+="<input class='searchString' id='"+id+"' name='"+id+"' type='text' value='' style='width:99%'></span>";
		    
		}else if(obj == "select"){//生成下拉框，查询方式"="
			text="<span><input type='hidden' class='searchField' value='"+id+"'>";
			
			if (value!=null){
				var values = value.split(",");
				text+="<select class='searchString' id='"+id+"' name='"+id+"'>";
				for (i=0;i<values.length;i++){
					text+="<option value='"+values[i]+"'>"+values[i]+"</option>";
				}
				text+="</select></span>";
			} else {
				text+="<select class='searchString' id='"+id+"' name='"+id+"'><option></option></select></span>";
			}					
		}else if(obj == "selectEnum"){//生成Enum下拉框，查询方式"="
			text="<span><input type='hidden' class='searchField' value='"+id+"'>";
			//alert(value);
			text+="<select class='searchString' id='"+id+"' name='"+id+"'>"+value+"</select>";
			text+="</span>";				
		}else if(obj == "checkbox"){//生成Checkbox
			//一个单元格放置checkbox情况
			if (value==null && value==undefined){
			   text="<span><input type='hidden' class='searchField' value='"+id+"'>";
			} else {
			   text="<span><input type='hidden' class='searchField' value='"+id+"'>"+value;
			}
			if (event==null){
			    text+="<input type='checkbox' class='searchString' id='"+id+"' name='"+id+"' value='FALSE' />";
			} else {
				text+="<input type='checkbox' class='searchString' id='"+id+"' name='"+id+"' value='FALSE' "+event+"/>";
			}
			text+="</span>";
			if (event==null){
			   $("#"+id).live("click",function(){
			      this.value=(this.checked==true ?"TRUE":"FALSE" )
		       });
			}
		}else if(obj == "checkboxs"){//生成Checkboxs
			text="<span name='"+id+"s'><input type='hidden' class='searchField' value='"+id+"'>";
			text+="<input type='hidden' class='searchString' id='"+id+"' name='"+id+"' value='' />";
			text+= value;
			text+="</span>";
			//$("input[name="+id+"]").ligerCheckBox();
			
		}else if(obj == "radios"){//生成radio
			text="<span name='"+id+"s'><input type='hidden' class='searchField' value='"+id+"'>";
			text+="<input type='hidden' class='searchString' id='"+id+"' name='"+id+"' value='' />";
			text+= value;
			text+="</span>";
			//$("input[name="+id+"]").ligerCheckBox();
			
		}else if (obj=="date")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的内容
		    text+="<input class='searchString' id='"+id+"' name='"+id+"' type='text' value='' size=10 onfocus='WdatePicker()'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='le'></span>";
		}else if (obj=="datestart")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的内容
		    text+="<input class='searchString Wdate' id='"+id+"' name='"+id+"' type='text' value=''  onfocus='WdatePicker({startDate:\"%y-%M-%d 00:00:00\",dateFmt:\"yyyy-MM-dd HH:mm:ss\",alwaysUseStartDate:true})'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='ge'></span>";
		}else if (obj=="dateend")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的内容
		    text+="<input class='searchString Wdate' id='"+id+"' name='"+id+"' type='text' value=''  onfocus='WdatePicker({startDate:\"%y-%M-%d 23:59:59\",dateFmt:\"yyyy-MM-dd HH:mm:ss\",alwaysUseStartDate:true})'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='le'></span>";
		}else if(obj=="datemonth"){
			text="<span><input type='hidden' class='searchField' value='"+id+"'>";
			//查询的内容
		    text+="<input class='searchString Wdate' id='"+id+"' name='"+id+"' type='text' value=''  onfocus='WdatePicker({startDate:\"%y-%M \",dateFmt:\"yyyy-MM \",alwaysUseStartDate:true})'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='le'></span>";
		}else if(obj=="inmonth"){
			text="<span><input type='hidden' class='searchField' value='"+id+"'>";
			//查询的内容
		    text+="<input class='searchString Wdate' id='"+id+"' name='"+id+"' type='text' value=''  onfocus='WdatePicker({startDate:\"%y%M\",dateFmt:\"yyyyMM\",alwaysUseStartDate:true})'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='le'></span>";
		}else if (obj=="autoinput")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的操作
		    text+="<input type='hidden' class='searchOper' value='cn' >";
		    //查询的内容
		    text+="<input  id='"+id+"_auto' name='"+id+"_auto' type='text' value='' style='width:99%'>";
		    text+="<input class='searchString' id='"+id+"' name='"+id+"' type='hidden' value='' style='width:99%'></span>";
		}else if (obj=="hidden")	{
			//查询的字段
		    text="<span><input type='hidden' class='searchField' value='"+id+"'>";
		    //查询的内容
		    text+="<input class='searchString' type='hidden' id='"+id+"' name='"+id+"' value="+value+">";
		    text+="</span>";
		}else if (obj=="input")	{//生成组合控件选择Dialog
			//查询的字段	
			id;
		    //text = "<span>"+document.getElementById(id).innerHTML+"</span>";
		    return;
		}
		document.getElementById('searchHeader').rows[row].cells[cell].innerHTML=text;
	
	 }
	
	function clearGroup(id,elem) {
		var group = $("input[name="+elem.name+"]");
		$("input[name="+elem.name+"]").each(function () {
			for (var i=0; i<group.length; i++) {
	            if (group[i] != elem) {
	                group[i].checked = false;
	            } else {
	            	$("#"+id).val(group[i].id);	            	
	            }
	        }
		}); 
	};

	function searchValueCheckBox(id,elem){
		var invalue="";
		$('input[name="c_'+id+'"]:checked').each(function(){ 
			if(invalue!=""){
				invalue+=","
			}
			invalue+=$(this).val();
			
		})
		$("#"+id).val(invalue);
	}
	function searchValueRadio(id,elem){
		$("#"+id).val(elem.value);
	}
	// 多条件查询  ex为node,也就是树节点 id为节点id，exrules为查询参数，url为查询地址， isClick是否执行默认的查询
	var multipleSearch = function(id ,isClick, exrules , url) {
		if (isClick){
		    var rules = exrules || "";
		    $("tbody tr td span", "#multipleSearchDialog").each(
				function(i) {
					var searchField = $(".searchField", this).val();
					var searchOper = $(".searchOper", this).val();
					var searchString = $(".searchString", this).val();
					//如果没有选择查询方式设置为“=”
					if(typeof searchOper == "undefined"){
						searchOper = "eq";
					}
					if (searchField && searchOper && searchString) {
						rules += ',{"field":"' + searchField + '","op":"'+ searchOper + '","data":"' + searchString + '"}';
					}
				});
		
		    //判断是否选择了分公司、部门
		    if($("#hid_field").val() && $("#hid_data").val()){
			    rules += ',{"field":"' + $("#hid_field").val() + '","op":"eq","data":"' + $("#hid_data").val() + '"}';
		    }

		    if (rules) {
			   rules = rules.substring(1);
		    }
		
		    var filtersStr = '{"groupOp":"AND","rules":[' + rules + ']}';
	
		
		    var manager = $(id).ligerGetGridManager();
		    var url = url || "list.do";
		    //alert(filtersStr)
		    manager.setOptions({url:url , parms : [{ name: 'filters', value: filtersStr},{ name : '_search' , value : true}] });
		    manager.changePage('first');
		} else {
			var manager = $(id).ligerGetGridManager();
			var url = url || "list.do";
			manager.setOptions({url:url});
			manager.changePage('first');
		}
	};
	
	function generateCondition(){
		var rules ="";
		$("tbody tr td span", "#multipleSearchDialog").each(
				function(i) {
					var searchField = $(".searchField", this).val();
					var searchOper = $(".searchOper", this).val();
					var searchString = $(".searchString", this).val();
					//如果没有选择查询方式设置为“=”
					if(typeof searchOper == "undefined"){
						searchOper = "eq";
					}
					if (searchField && searchOper && searchString) {
						rules += ',{"field":"' + searchField + '","op":"'+ searchOper + '","data":"' + searchString + '"}';
					}
				});
		// 方贤银 2013-01-04 增加
	    if($("#hid_field").val() && $("#hid_data").val()){
		    rules += ',{"field":"' + $("#hid_field").val() + '","op":"eq","data":"' + $("#hid_data").val() + '"}';
	    }
		if (rules) {
		    rules = rules.substring(1);
		}
		var filtersStr = '{"groupOp":"AND","rules":[' + rules + ']}';
		return filtersStr;
	}
	

	// 清空页面查询条件
	var clearSearch = function() {
		$('input:text').val("");
		$("tbody tr td span", "#multipleSearchDialog").each(function(i) {
			$(".searchString", this).val("");
		});
	};

	// 日期控件有先后顺序问题，设置到此无效
	/*$("input[name='time']").focus(function(){
		WdatePicker();
	});*/

	//选择部门查询
	var searchOperation = function(id){
		if(id!=null && id.indexOf("f_")!=-1){
			id = id.substring(id.indexOf("f_")+2,id.length);
			//等于0表示选择了最根目录
			if(id!=0){
				$("#hid_field").val("department.branch.id");
				$("#hid_data").val(id);
				$("#add").attr({"class":"icon"});//改变添加按钮样式
				$("#add").unbind("click");//禁用add标签事件
			}else{
				$("#hid_field").val("");
				$("#hid_data").val("");
				$("#add").attr({"class":"icon"});//改变添加按钮样式
				$("#add").unbind("click");//禁用add标签事件
			}
		}else{
			$("#hid_field").val("department.id");
			$("#hid_data").val(id);
			$("#add").attr({"class":"add"});//改变添加按钮样式
			$("#add").click(function(){  
		            add();  
		    });
		}
		multipleSearch("#table1");
		
	};
	

	var delId;
	// 显示弹出操作提示框
	function delDialog() {
		delId = "";
	    var selectedRowIds = $("#table1").jqGrid("getGridParam","selarrrow");
	    var len = selectedRowIds.length;
	    for(var i = 0;i < len ;i ++) {
	    	if(i!=0)
	    		delId+=",";
	    	//获得行数据
	    	var rowData = $("#table1").jqGrid("getRowData", selectedRowIds[i]);
	    	delId += rowData.id;
	    }
	    if(delId.length<1){
	    	ShowAlert("ok", "提示框","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">请先选择要删除的数据，再点击删除</h3>", 300, 150);
	    	return false;
	    }
		ShowConfirm("ok", "确定", "common/msgdialog.jsp", 300, 150);
	}

	// 删除
	function del() {
		//alert("delId="+delId);
		$.ajax({
			type : "POST",
			url : "delete/" + delId + ".do",
			//data: "{ids:"+ids+"}",
			error : function(data) {
				ShowAlert("ok", "提示框","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+ data + "</h3>", 300, 150);
				delId = "";
			},
			success : function(data) {
				//$("#table1").jqGrid("delRowData", delId);
				$("#table1").trigger("reloadGrid");
				ShowAlert("ok", "提示框","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+ data + "</h3>", 300, 150);
				delId = "";
			}
		});
	}

	//定义公共的验证函数方法
    function define_common_method() {
	
	/* 设置默认属性 */
	$.validator.setDefaults({
		submitHandler : function(form) {
			form.submit();
		}
	});

	//添加自定义校验函数
	$.validator.addMethod("charNo",function(value, element) {
		var length = value.length;
		var your_tel = /[\W]/g;
		return this.optional(element)
				|| (length <= 8 && !your_tel.test(value));
	}, "请输入英文字符或数字！");

	//添加验证操作名称的校验函数
	$.validator.addMethod("charString", function(value, element) {
		var length = value.length;
		var your_tel = /[^\a-zA-Z\u4E00-\u9FA5]/g;
		var your_tel2 = /^[A-Za-z]*$/;
		return this.optional(element)
				|| (length <= 20 && !your_tel.test(value));
	}, "请输入中文或英文名称");

	// 字符验证
	jQuery.validator.addMethod("stringCheck", function(value, element) {
		return this.optional(element) || /^[\u0391-\uFFE5\w .]+$/.test(value);
	}, "只能包括中文字、英文字母、数字和下划线");
	
	// 字母验证
	jQuery.validator.addMethod("letterCheck", function(value, element) {
		return this.optional(element) || /^[A-Za-z ]+$/.test(value);
	}, "只能包括英文字母和空格");

	// 中文字两个字节
	jQuery.validator.addMethod("byteRangeLength", function(value,element, param) {
		var length = value.length;
		for ( var i = 0; i < value.length; i++) {
			if (value.charCodeAt(i) > 127) {
				length++;
			}
		}
		return this.optional(element)|| (length >= param[0] && length <= param[1]);
	}, "请确保输入的值在3-15个字节之间(一个中文字算2个字节)");

	// 身份证号码验证
	jQuery.validator.addMethod("isIdCardNo", function(value, element) {
		value = value.toUpperCase();//转换大于X
		var idCard = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/;
		return this.optional(element) || (idCard.test(value));
	}, "请正确输入您的身份证号码");

	// 电话号码验证
	jQuery.validator.addMethod("isTel", function(value, element) {
		var tel = /^\d{3,4}-?\d{7,9}$/; // 电话号码格式010-12345678
		return this.optional(element) || (tel.test(value));
	}, "请正确填写您的电话号码");

	 //联系电话(手机/电话皆可)验证
	jQuery.validator.addMethod("isPhone", function(value, element) {
		var length = value.length;
		var mobile = /^(\d{3,4}-)?\d{7,8}(-\d{3,4})?$|(^0{0,1}(13[0-9]|15[0-9]|18[7-9])[0-9]{8}$)/;
		var tel = /^\d{3,4}-?\d{7,9}$/;
		return this.optional(element) || (tel.test(value) || mobile.test(value));
	}, "请正确填写您的联系电话");

	// 邮政编码验证
	jQuery.validator.addMethod("isZipCode", function(value, element) {
		var zipCode = /^[0-9]{6}$/;
		return this.optional(element) || (zipCode.test(value));
	}, "请正确填写您的邮政编码");
	
	// 薪水验证
	jQuery.validator.addMethod("numCheck", function(value, element) {
		var num = /^[0-9]+(\.[0-9]+)*$/;
		return this.optional(element) || (num.test(value));
	}, "请正确填写您的薪水");
	
	// 验证数字，可以带两位小数点
	jQuery.validator.addMethod("checkNumber", function(value, element) {
		
		reg = /^[0-9]+(\.[0-9]+)*$/; 
		var result = reg.test(value); 
		if(result) 	{
			result=!(value.split('.').length>1 && value.split('.')[1].length>2); 
		} 
		
		return this.optional(element) || result;
	}, "<p>允许输入两位小数的金额");
	
	// 验证选择项，必须从下拉框的非第一个选择
	jQuery.validator.addMethod("selectMust", function(value, element) {
		var index =  $(element).get(0).selectedIndex;
		if(index == 0)
			return  false;
		return  true;
	}, "必须选择");
	
	// 验证选择项，必须从为yyyy-MM-dd格式的时间数据 add by qs 20120329
	jQuery.validator.addMethod("isDate", function(value, element) {
		var b =  /^\d[4]-\d[2]-\d[2]$/.test($(element).val()); 
		if(b)
			return  false;
		return  true;
	}, "请输入yyyy-MM-dd格式的日期");

}

var v_key="";
var v_value="";
//单用户选择弹出查询框 fName为父页面ID
var searchUser = function(key,value,fName){
	//undefined 未传入参数
	if(fName==undefined || fName.length<1)
		fName = "operate";
	var url = "user/openUserDialog/"+fName+".do";
	v_key = key;
	v_value = value;
	ShowChildIframe("childPage","search",url,650,480);
};

//单用户赋值
var setValue = function(){
	eval('var obj='+$("#hidKey").val()+'');
	$("#"+v_key).val(obj.id);
	$("#"+v_value).val(obj.name);
	CloseChildDialog("childPage");//对闭指定对话框
};

//多用户选择 查询框 fName为父页面ID
var selectUsers = function(fName){
	//undefined 未传入参数
	if(fName==undefined || fName.length<1)
		fName = "child";//默认名称
	var url = "globalURL/user/"+fName+".do";
	ShowChildIframe("selectUser", "选择用户", url, 630, 500);
};

//多用户赋值
function setUserValue(){
	$("#userIds").val($("#hidKey").val());
	$("#userNames").val($("#hidValue").val());
	$("#hidKey").val("");
	$("#hidValue").val("");
	CloseChildDialog("selectUser");//关闭指定对话框
}

//清空KEY\VALUE组合框（根据NAME没值清空）
var clearText = function(obj,key){
	if(obj.value=="")
		$("#"+key).val("");
};

//清空 KEY\VALUE 组合框
function clearValue(key,keyName){
	$("#"+key).val("");
	$("#"+key+"Name").val("");
	$("#"+keyName).val("");
}

//关闭对话框
function closeDialog(){
	try{
		var manager = W.$("#table1").ligerGetGridManager();
		manager.loadData();
		api.close();//刷新JQGRID
	}catch(e){
		
	}
	
	CloseDialog();
}

//弹出部门选择对话框
function selectDeptDialog(){
	var url = "globalURL/dept.do";
	ShowIframe("deptDialog","select department",url,300,450);
}

//编辑页面弹出部门选择
var selectDeptChildDialog = function(){
	var url = "globalURL/dept.do";
	ShowChildIframe("deptDialog","select department",url,300,450);
};

//验证最多输入两位小数的数字
var checkNumber = function (e,obj){ 
	var key = window.event ? e.keyCode : e.which; 
	//左移右移退格
	if(e.keyCode==37 || e.keyCode==39 || e.keyCode==8)
		return true;
	
	var keychar = String.fromCharCode(key);

	reg = /\d|\./; 
	var result = reg.test(keychar);
	if(result){
		if(e.keyCode==46) 
			result=!(obj.value.split('.').length>1);
		else 
			result=!(obj.value.split('.').length>1&&obj.value.split('.')[1].length>1); 
	} 
	
	if(!result)	{ 
		return false; 
	} else {
		return true; 
	}
};

var async_submit=true;
var getReturnMessage = function(url,form,success_function,error_function){
	if(!async_submit){//防止重复提交
		return false;
	}

	var async_showload= $.ligerDialog.waitting('正在保存中,请稍候...');
	async_submit=false;
	var options = { 
            url :  url, 
            type : "post", 
            dataType:"json",
            async:false,
            error: function(response){
            	async_submit=true;
            	async_showload.close();
            	if (response && response.success == "false") {
            		if (frameElement.api!=undefined){
                  	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>",300,150);
                  	} else {
                  	   $.ligerDialog.error(response.infor);
                  	} 
            	} else {
                	if (frameElement.api!=undefined){
                 	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.responseText+"</h3>",300,150);
                 	} else {
                 	   $.ligerDialog.error(response.infor);
                 	}            		
            	}
            	if(typeof(eval(error_function))=="function"){
            	    error_function();
            	}
            },     
            success: function(response){
            	async_submit=true;
            	async_showload.close();
            	//判断返回的数据，如果是Add的数据要保存的Id返回回来
            	//否则返回提示成功信息即可
            	
            	
            	 if(response.success=="true" || response.success==true){
    				 $("#id").val(response.id);
    				 if(typeof(eval(success_function))=="function"){
    	     	    		if(response.success=="true" || response.success==true){        	    			
    	     	    			 success_function(); 
    	     	    		}
    	        			          			 
    	        		 }  
    				 //方炜删除
    				// $.ligerDialog.success("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
    				 //方炜于2013-01-09加(确定就关闭窗口)
    				 $.ligerDialog.alert("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>","",'success',function(){
    					 var api = frameElement.api, W = api.opener; 
    					 api.close();
    				 });
 	    			// $.ligerDialog.success("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
 	    		}else{
 	    			 $.ligerDialog.error("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
 	    		}	 
            			
           		 
            }
    };
    setTimeout((function(opt){
            return function(){
            	if (form!=undefined){
                    $('#'+form).ajaxSubmit(opt);
            	} else {
                    $('#inputForm').ajaxSubmit(opt);
            	}

            };
    })(options), 300); 
    return false; 
};

//add by gzy-14-11-2
var async_submitTwo=true;
var getReturnMessageTwo = function(url,form,success_function,error_function){
	if(!async_submitTwo){//防止重复提交
		return false;
	}

	var async_showload= $.ligerDialog.waitting('正在保存中,请稍候...');
	async_submitTwo=false;
	var options = { 
            url :  url, 
            type : "post", 
            dataType:"json",
            async:false,
            error: function(response){
            	async_submit=true;
            	async_showload.close();
            	if (response && response.success == "false") {
            		if (frameElement.api!=undefined){
                  	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>",300,150);
                  	} else {
                  	   $.ligerDialog.error(response.infor);
                  	} 
            	} else {
                	if (frameElement.api!=undefined){
                 	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.responseText+"</h3>",300,150);
                 	} else {
                 	   $.ligerDialog.error(response.infor);
                 	}            		
            	}
            	if(typeof(eval(error_function))=="function"){
            	    error_function();
            	}
            },     
            success: function(response){
            	async_submit=true;
            	async_showload.close();
            	//判断返回的数据，如果是Add的数据要保存的Id返回回来
            	//否则返回提示成功信息即可
            	 if(response.success=="true" || response.success==true){
            		 //$("#id").val(response.id);
    				 if(typeof(eval(success_function))=="function"){
	     	    		 if(response.success=="true" || response.success==true){        	    			
	     	    			 success_function(); 
	     	    		 }
    	        	 }
    				 $.ligerDialog.success("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>","",function(){
    					
    					 
    					 grid.loadData();
    					 async_submitTwo = true;
    				 });
 	    		}else{
 	    			 $.ligerDialog.error("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
 	    		}	 
            }
    };
    setTimeout((function(opt){
            return function(){
            	if (form!=undefined){
                    $('#'+form).ajaxSubmit(opt);
            	} else {
                    $('#inputForm').ajaxSubmit(opt);
            	}

            };
    })(options), 300); 
    return false; 
};

//get page height
function pageHeight(){
    if($.browser.msie){
        return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
        document.body.clientHeight;
    }else{
        return self.innerHeight;
    }
};
 
//get page width
function pageWidth(){
    if($.browser.msie){
        return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
        document.body.clientWidth;
    }else{
        return self.innerWidth;
    }
};

function htmlToCode(s) 
{ 
   if(s == null){ 
      return ""; 
   } else { 
      s = replace(s, "", "\n\n"); 
      s = replace(s, "", "\r\n"); 
      s = replace(s, "&nbsp;&nbsp;&nbsp;&nbsp;", "\t"); 
      s = replace(s, "&nbsp;", " "); 
      s = replace(s, "&lt;", "<"); 
      s = replace(s, "&gt;", ">"); 
      s = replace(s, "&amp;", "&"); 
      return s; 
    } 
}  

//去掉前后空格：
function trim(m){   
	m.replace(/(^\s*)|(\s*$)/g, "");   
}

//在必填项前加*号
function createRequireMark(requireIds){
	var requireIdArr=requireIds.split(",");
	$(requireIdArr).each(function(index,value){
		if($("#"+value).hasClass("shortInput")||
				$("#"+value).hasClass("longInput")||
				$("#"+value).hasClass("Wdate")||
				$("#"+value).is("select")){
			$("#"+value).parent().append($("<span class='required' >*</span>"));
		}else{
			$("#"+value).addClass("required");
		}
		
		
	});
}

//2012-5-15钱水 添加清空查询form方法
function clearSearchForm(){
	$("form :input[name!='_searchConditions']").each(function(index,value) {
		$(value).val("");
	});
}

/** 
 * desc : 合并指定表格（表格id为table_id）指定列（列数为table_colnum）的相同文本的相邻单元格   
 * @table_id 表格id : 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ，此参数应为 #data    
 * @table_colnum   : 为需要合并单元格的所在列.参考jQuery中nth-child的参数.若为数字，从最左边第一列为1开始算起;"even" 表示偶数列;"odd" 表示奇数列; "3n+1" 表示的列数为1、4、7、......  
 * @table_minrow ? : 可选的,表示要合并列的行数最小的列,省略表示从第0行开始 (闭区间)  
 * @table_maxrow ? : 可选的,表示要合并列的行数最大的列,省略表示最大行列数为表格最后一行 (开区间)  
 */  
 function table_rowspan(table_id,table_colnum)  
 {  
     if(table_colnum=="even"){  
     table_colnum = "2n";  
     }  
     else if(table_colnum=="odd"){  
     table_colnum = "2n+1";  
     }  
     else{  
     table_colnum = ""+table_colnum;  
     }  
     var cols=[];  
     var all_row_num = $(table_id+" tr td:nth-child(1)").length;  
     var all_col_num = $(table_id+" tr:nth-child(1)").children().length;  
     if(table_colnum.indexOf("n")==-1){  
     cols[0] = table_colnum;  
     }  
     else{  
     var n = 0;  
     var a = table_colnum.substring(0,table_colnum.indexOf("n") );  
     var b= table_colnum.substring(table_colnum.indexOf("n")+1);  
     //alert("a="+a+"b="+(b==true));  
     a = a?parseInt(a):1;  
     b = b?parseInt(b):0;  
     //alert(b);  
     while(a*n+b<=all_col_num){  
         cols[n] = a*n+b;  
         n++;  
     }  
     }  
     var table_minrow = arguments[2]?arguments[2]:0;  
     var table_maxrow = arguments[3]?arguments[3]:all_row_num+1;      
     var table_firsttd = "";    
     var table_currenttd = "";    
     var table_SpanNum = 0;  
     for(var j=0;j<cols.length;j++){  
         $(table_id + " tr td:nth-child(" + cols[j] + ")").slice(table_minrow, table_maxrow).each(function (i) {  
             var table_col_obj = $(this);  
             if (table_col_obj.html() != " ") {  
                 if (i == 0) {  
                     table_firsttd = $(this);  
                     table_SpanNum = 1;  
                 }  
                 else {  
                     table_currenttd = $(this);  
                     if (table_firsttd.text() == table_currenttd.text()) {  
                         table_SpanNum++;  
                         table_currenttd.hide(); //remove();    
                         table_firsttd.attr("rowSpan", table_SpanNum);  
                     } else {  
                         table_firsttd = $(this);  
                         table_SpanNum = 1;  
                     }  
                 }  
             }  
         });  
     }  
 }  

 /** 
 * desc : 合并指定表格（表格id为table_id）指定行（行数为table_rownum）的相同文本的相邻单元格     
 * @table_id 表格id : 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ，此参数应为 #data    
 * @table_rownum   : 为需要合并单元格的所在行.参考jQuery中nth-child的参数.若为数字，从最左边第一列为1开始算起;"even" 表示偶数行;"odd" 表示奇数行; "3n+1" 表示的行数为1、4、7、......  
 * @table_mincolnum ? : 可选的,表示要合并行中的最小列,省略表示从第0列开始(闭区间) 
 * @table_maxcolnum ? : 可选的,表示要合并行中的最大列,省略表示表格的最大列数(开区间)  
 */    
function table_colspan(table_id,table_rownum){    
     //if(table_maxcolnum == void 0){table_maxcolnum=0;}  
     var table_mincolnum = arguments[2]?arguments[2]:0;  
     var table_maxcolnum;  
     var table_firsttd = "";    
     var table_currenttd = "";    
     var table_SpanNum = 0;    
     $(table_id + " tr:nth-child(" + table_rownum + ")").each(function(i){    
         table_row_obj = $(this).children();  
         table_maxcolnum = arguments[3]?arguments[3]:table_row_obj.length;    
         table_row_obj.slice(table_mincolnum,table_maxcolnum).each(function(i){    
             if(i==0){    
                 table_firsttd = $(this);    
                 table_SpanNum = 1;    
             }else if((table_maxcolnum>0)&&(i>table_maxcolnum)){    
                 return "";    
             }else{    
                 table_currenttd = $(this);    
                 if(table_firsttd.text()==table_currenttd.text()){    
                     table_SpanNum++;   
                     if(table_currenttd.is(":visible")){  
                         table_firsttd.width(parseInt(table_firsttd.width())+ parseInt(table_currenttd.width()));  
                             }     
                     table_currenttd.hide(); //remove();    
                     table_firsttd.attr("colSpan",table_SpanNum);  
                 }else{    
                     table_firsttd = $(this);    
                     table_SpanNum = 1;    
                 }    
             }    
         });    
     });    
 }
// liubo 2014 11 6
async_submit_three=true;
var getReturnMessageThree = function(url,form,success_function,error_function,obj,data,print,where,close,checai){ //obj 主表对象 data 行记录 print 是不是为提交状态(提交才打印) where  什么的打印 区别 例如 其他入库，其他出库等 close 是否关闭页面
	if(!async_submit_three){//防止重复提交
		return false;
	}
	var async_showload= $.ligerDialog.waitting('正在保存中,请稍候...');
	async_submit_three=false;
	var options = { 
            url :  url, 
            type : "post", 
            dataType:"json",
            async:false,
            error: function(response){
            	async_submit_three=true;
            	async_showload.close();
            	if (response && response.success == "false") {
            		if (frameElement.api!=undefined){
                  	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>",300,150);
                  	} else {
                  	   $.ligerDialog.error(response.infor);
                  	} 
            	} else {
                	if (frameElement.api!=undefined){
                 	   ShowChildAlertBlowup("ok","Message","<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.responseText+"</h3>",300,150);
                 	} else {
                 	   $.ligerDialog.error(response.infor);
                 	}            		
            	}
            	if(typeof(eval(error_function))=="function"){
            	    error_function();
            	}
            },     
            success: function(response){
            	async_submit_three=true;
            	async_showload.close();
            	//判断返回的数据，如果是Add的数据要保存的Id返回回来
            	//否则返回提示成功信息即可
            	
            	
            	 if(response.success=="true" || response.success==true){
            		 var guanbi=true;
            		 if(close!=undefined){
            			 guanbi=close;
            		 }
    				 if(typeof(eval(success_function))=="function"){
    	     	    		if(response.success=="true" || response.success==true){        	    			
    	     	    			 success_function(); 
    	     	    		}
    	        			          			 
    	        		 }  
    				 $.ligerDialog.alert("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>","",'success',function(){
    					 var munber='';
    					 var api = frameElement.api, W = api.opener;
    					 if(print){
    					 $.ligerDialog.confirm('是否打印', function (yes) {
    						 if(where =='prodispat'){//生产派工把派工取消单的单号
    							 munber=response.code;
    						 }
    						 if(yes){
            					window.parent.parent.loadPrint(obj,data,where,true,munber,checai);
    						 }
    						 if(guanbi){
    							 api.close();
    						 }else{
    							 try {
    								 grid.loadData();//派工时
								} catch (e) {
									addressGrid.loadData();
								}
    							 async_submit_three=true;
    						 }
    					  });
    					 }else{
    						 if(guanbi){
    							 try {
    								 grid.loadData();//派工时
								} catch (e) {
									addressGrid.loadData();
								}
    							 api.close();
    						 }else{
    							 try {
    								 grid.loadData();//派工时
								} catch (e) {
									addressGrid.loadData();
								}
    							 async_submit_three=true;
    						 }
    					 }
    					
    				 });
 	    			// $.ligerDialog.success("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
 	    		}else{
 	    			 $.ligerDialog.error("<h3 style=\"font-size:14px;text-align:center;padding:25px 0;\">"+response.infor+"</h3>");
 	    		}	 
            			
           		 
            }
    };
    setTimeout((function(opt){
            return function(){
            	if (form!=undefined){
                    $('#'+form).ajaxSubmit(opt);
            	} else {
                    $('#inputForm').ajaxSubmit(opt);
            	}

            };
    })(options), 300); 
    return false; 
};
